from apiflask import APIBlueprint
from flask import request, jsonify
# from flask_jwt_extended import create_access_token
from flask.views import MethodView
# from applications.models import User
from flask_jwt_extended import jwt_required, current_user

#

auth_bp = APIBlueprint('auth', __name__, url_prefix='/auth')


#
#
#

@auth_bp.route('/login')
class Index(MethodView):
    def post(self):
        data = request.json
        username = data.get('username', None)
        password = str(data.get('password', None))
        # user = User.query.filter_by(username=username).first()
        #
        # if not user or not user.check_password(password):
        #     return jsonify("Wrong username or password"), 401

        # access_token = create_access_token(identity=user)
        # return jsonify(access_token=access_token)
        return '1'


@auth_bp.route('/test')
class Test(MethodView):
    @jwt_required()
    def post(self):
        return jsonify(
            id=current_user.id,
            full_name=current_user.username,
            username=current_user.phone,
        )
